/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */

package com.hibernate.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "WEBSITE")
public class Website extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "网站";
	public static final String ALIAS_ID = "ID";
	public static final String ALIAS_USER_ID = "所属用户";
	public static final String ALIAS_NAME = "名称";
	public static final String ALIAS_HOST = "域名";
	public static final String ALIAS_TYPE_ID = "类型";
	public static final String ALIAS_LABEL_AMOUNT = "栏目数量";
	public static final String ALIAS_AD_SITE_AMOUNT = "广告位数量";
	public static final String ALIAS_LINKMAN = "联系人姓名";
	public static final String ALIAS_EMAIL = "联系人Email";
	public static final String ALIAS_MOBILE = "联系人手机";
	public static final String ALIAS_PHONE = "联系人电话";
	public static final String ALIAS_REMARK = "备注";
	public static final String ALIAS_CREATION_TIME = "创建时间";
	public static final String ALIAS_STATUS = "状态";
	public static final String ALIAS_TYPE_STR = "类型";
	public static final String ALIAS_CHANNELS_ID = "所属渠道";
	public static final String ALIAS_OTHER_CODE = "外部编号";
	public static final String ALIAS_ALEX = "Alex排行";
	public static final String ALIAS_CHEAT = "作弊情况";
		
	//date formats
	public static final String FORMAT_CREATION_TIME = DATE_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;
	@Length(max=255)
	private String otherCode;
	@NotBlank @Length(max=200)
	private java.lang.String name;
	@NotBlank @Length(max=50)
	private java.lang.String host;
	@NotNull 
	private Long typeId;
	@NotNull @Length(max=100)
	private String typeStr;
	@NotNull 
	private Long labelAmount;
	@NotNull 
	private Long adSiteAmount;
	@NotBlank @Length(max=50)
	private java.lang.String linkman;
	@NotBlank @Length(max=50)
	private java.lang.String email;
	@NotBlank @Length(max=11)
	private java.lang.String mobile;
	@Length(max=20)
	private java.lang.String phone;
	private String phoneArea;
	private String phoneExt;
	@Length(max=1000)
	private java.lang.String remark;
	@NotNull 
	private java.util.Date creationTime;
	@NotBlank @Length(max=1)
	private java.lang.String status;
	@NotNull
	private Long channelsId;
	
	private String loginName;
	
	private String loginPass;
	
	private Integer loginType;

	@Length(max=20)
	private String newType;
	private Long alex;
	@Length(max=30)
	private String cheat;
	//columns END


	public Website(){
	}

	public Website(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id 	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 200)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "HOST", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getHost() {
		return this.host;
	}
	
	public void setHost(java.lang.String value) {
		this.host = value;
	}
	
	@Column(name = "TYPE_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getTypeId() {
		return this.typeId;
	}
	
	public void setTypeId(Long value) {
		this.typeId = value;
	}
	
	@Column(name = "LABEL_AMOUNT", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getLabelAmount() {
		return this.labelAmount;
	}
	
	public void setLabelAmount(Long value) {
		this.labelAmount = value;
	}
	
	@Column(name = "AD_SITE_AMOUNT", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getAdSiteAmount() {
		return this.adSiteAmount;
	}
	
	public void setAdSiteAmount(Long value) {
		this.adSiteAmount = value;
	}
	
	@Column(name = "LINKMAN", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getLinkman() {
		return this.linkman;
	}
	
	public void setLinkman(java.lang.String value) {
		this.linkman = value;
	}
	
	@Column(name = "EMAIL", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getEmail() {
		return this.email;
	}
	
	public void setEmail(java.lang.String value) {
		this.email = value;
	}
	
	@Column(name = "MOBILE", unique = false, nullable = false, insertable = true, updatable = true, length = 11)
	public java.lang.String getMobile() {
		return this.mobile;
	}
	
	public void setMobile(java.lang.String value) {
		this.mobile = value;
	}
	
	@Column(name = "PHONE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getPhone() {
		return this.phone;
	}
	
	public void setPhone(java.lang.String value) {
		this.phone = value;
	}
	@Transient
	public String getPhoneArea() {
		return phoneArea;
	}

	public void setPhoneArea(String phoneArea) {
		this.phoneArea = phoneArea;
	}
	@Transient
	public String getPhoneExt() {
		return phoneExt;
	}

	public void setPhoneExt(String phoneExt) {
		this.phoneExt = phoneExt;
	}

	@Column(name = "REMARK", unique = false, nullable = true, insertable = true, updatable = true, length = 1000)
	public java.lang.String getRemark() {
		return this.remark;
	}
	
	public void setRemark(java.lang.String value) {
		this.remark = value;
	}
	
	
	@Column(name = "LOGIN_NAME")
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	@Column(name = "LOGIN_PASS")
	public String getLoginPass() {
		return loginPass;
	}

	public void setLoginPass(String loginPass) {
		this.loginPass = loginPass;
	}

	@Column(name = "LOGIN_TYPE")
	public Integer getLoginType() {
		return loginType;
	}

	public void setLoginType(Integer loginType) {
		this.loginType = loginType;
	}

	@Transient
	public String getCreationTimeString() {
		return DateConvertUtils.format(getCreationTime(), FORMAT_CREATION_TIME);
	}
	public void setCreationTimeString(String value) {
		setCreationTime(DateConvertUtils.parse(value, FORMAT_CREATION_TIME,java.util.Date.class));
	}
	
	@Column(name = "CREATION_TIME", unique = false, nullable = false, insertable = true, updatable = true, length = 7)
	public java.util.Date getCreationTime() {
		return this.creationTime;
	}
	
	public void setCreationTime(java.util.Date value) {
		this.creationTime = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.String value) {
		this.status = value;
	}
	
	private Set labels = new HashSet(0);
	public void setLabels(Set<Label> label){
		this.labels = label;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER, mappedBy = "website")
	@OrderBy("name")
	public Set<Label> getLabels() {
		return labels;
	}
	
	private WebsiteType websiteType;
	public void setWebsiteType(WebsiteType websiteType){
		if(websiteType != null)
			websiteType.getName();
		this.websiteType = websiteType;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "TYPE_ID",nullable = false, insertable = false, updatable = false) 
	})
	public WebsiteType getWebsiteType() {
		return websiteType;
	}
	
	public void setTypeStr(String typeStr) {
		this.typeStr = typeStr;
	}
	
	@Column(name = "TYPE_STR", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public String getTypeStr() {
		return typeStr;
	}

	public void setChannelsId(Long channelsId) {
		this.channelsId = channelsId;
	}
	
	@Column(name = "CHANNELS_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getChannelsId() {
		return channelsId;
	}
	
	private Channels channels;
	public void setChannels(Channels channels) {
		if(channels != null)
			channels.getLinkman();
		this.channels = channels;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.EAGER)
	@JoinColumns({
		@JoinColumn(name = "CHANNELS_ID",nullable = false, insertable = false, updatable = false) 
	})
	public Channels getChannels() {
		return channels;
	}
	@Column(name = "OTHER_CODE", unique = false, nullable = true, insertable = true, updatable = true, length = 255)
	public String getOtherCode() {
		return this.otherCode;
	}
	
	public void setOtherCode(String value) {
		this.otherCode = value;
	}
	

	@Column(name = "ALEX", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public Long getAlex() {
		return this.alex;
	}
	
	public void setAlex(Long value) {
		this.alex = value;
	}
	
	@Column(name = "CHEAT", unique = false, nullable = true, insertable = true, updatable = true, length = 30)
	public String getCheat() {
		return this.cheat;
	}
	
	public void setCheat(String value) {
		this.cheat = value;
	}

	public void setNewType(String newType) {
		this.newType = newType;
	}
	
	@Column(name = "NEW_TYPE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public String getNewType() {
		return newType;
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "网站";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getName();
	}
}

